package com.gxa.order.util;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeFastpayRefundQueryRequest;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;

public  class PayUtil {
    /**
     * 支付API
     * @param No
     * @param money
     * @param coname
     * @param response
     */
    public static void od(String No,String money,String coname,HttpServletResponse response){
        String privateKey="MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCfCft3kAN4Q9emDemsPK/25AFSgR4G894J3SR2COatUG/biD/qJv0L/HLJJSi6h5MJz7t3LAeAdTeuu6rV4+8xNA0ZG3T8YAso9lLi6GjVp3I33Hg8oh9pJL4wpyh0HHS4fp/zYbj/5DY/Au6qx7ngCWNpfugHLScmoT9aAG3Tbozd04oYn5MplWZApI1Y8fXOL7IZeIFjU9oUTUsPL9ryvqlHYeaNgnhqlYZXPOijDx1cvr5dzoAO0TKfh/M1g6jHVHEptxbl3irg+3ypf+MRncFe/KX0hHGM0MFmQLLlGUhxKBQodr7mpMHdy/plQrIYjS3+9L/qFAwX2LApWbTRAgMBAAECggEBAJojFZo6dHJx5iZlI40vwCdbscBhrVV1s0QCFV1koRVmeRLeyXtJ0ER2plU2c3PdA/Alaf5FKPwiHxZ1gkwMvn0EgpFL4CTdfNN1cL3EHB6+S9/CCLJTOngwCTikOXvXPHS3HJTIqIExkDWfxOq16fstfjD3sy+JXoF9FCZJdifMWMRJB1KSMIx/YDKbsmUebMGCcy6VIeGRnJ8KjuzOxiKO76Myi90oOvzD2DJELS4xUyXYU4Ow+x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ZeeUiaeCgmpl6DYK1kCbFw7d/XB4Rktyy3j/xHJoIqvVtWPWmAOLpth3cXZ3JtDwhk7vBY0pj8txyFNLjMGpNO3lWDTkO0JgZAQGrrKE+c2CjKTjDkXLqX+1+FzgWBlt6cZxT2vda2lJNM/9D3Pev7oh54fqomG9DGDWoEQg5KmIxcgKIjDVuy/CCnGeMK3LPry3injykbe4K4AdebLjIp/LhcaRcP6+32YQ45WVXs0j5fBv/jvcdt2KbdYzyhT/iwqF2cFNddg0bf72A9eKik6r7JlmKKqvlawIDAQAB";

        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do","2021000122674099",privateKey,"json","UTF-8",publicKey,"RSA2");
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
//异步接收地址，仅支持http/https，公网可访问
        request.setNotifyUrl("");
//同步跳转地址，仅支持http/https
        request.setReturnUrl("");
/******必传参数******/
        JSONObject bizContent = new JSONObject();
//商户订单号，商家自定义，保持唯一性
        bizContent.put("out_trade_no", No);
//支付金额，最小值0.01元
        bizContent.put("total_amount", money);
//订单标题，不可使用特殊符号
        bizContent.put("subject", coname);
//电脑网站支付场景固定传值FAST_INSTANT_TRADE_PAY
        bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");

/******可选参数******/
//bizContent.put("time_expire", "2022-08-01 22:00:00");

//// 商品明细信息，按需传入
//JSONArray goodsDetail = new JSONArray();
//JSONObject goods1 = new JSONObject();
//goods1.put("goods_id", "goodsNo1");
//goods1.put("goods_name", "子商品1");
//goods1.put("quantity", 1);
//goods1.put("price", 0.01);
//goodsDetail.add(goods1);
//bizContent.put("goods_detail", goodsDetail);

//// 扩展信息，按需传入
//JSONObject extendParams = new JSONObject();
//extendParams.put("sys_service_provider_id", "2088511833207846");
//bizContent.put("extend_params", extendParams);

        request.setBizContent(bizContent.toString());

        String form="";
        try {
            form = alipayClient.pageExecute(request).getBody(); //调用SDK生成表单
            response.setContentType("text/html;charset=UTF-8");
            response.getWriter().write(form);//直接将完整的表单html输出到页面
            response.getWriter().flush();
            response.getWriter().close();
        } catch (AlipayApiException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    /**
     * 支付后订单查询
     * @param num
     * @return
     */
    public static  String select(String num){
        String privateKey="MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCfCft3kAN4Q9emDemsPK/25AFSgR4G894J3SR2COatUG/biD/qJv0L/HLJJSi6h5MJz7t3LAeAdTeuu6rV4+8xNA0ZG3T8YAso9lLi6GjVp3I33Hg8oh9pJL4wpyh0HHS4fp/zYbj/5DY/Au6qx7ngCWNpfugHLScmoT9aAG3Tbozd04oYn5MplWZApI1Y8fXOL7IZeIFjU9oUTUsPL9ryvqlHYeaNgnhqlYZXPOijDx1cvr5dzoAO0TKfh/M1g6jHVHEptxbl3irg+3ypf+MRncFe/KX0hHGM0MFmQLLlGUhxKBQodr7mpMHdy/plQrIYjS3+9L/qFAwX2LApWbTRAgMBAAECggEBAJojFZo6dHJx5iZlI40vwCdbscBhrVV1s0QCFV1koRVmeRLeyXtJ0ER2plU2c3PdA/Alaf5FKPwiHxZ1gkwMvn0EgpFL4CTdfNN1cL3EHB6+S9/CCLJTOngwCTikOXvXPHS3HJTIqIExkDWfxOq16fstfjD3sy+JXoF9FCZJdifMWMRJB1KSMIx/YDKbsmUebMGCcy6VIeGRnJ8KjuzOxiKO76Myi90oOvzD2DJELS4xUyXYU4Ow+xa4GclO29VTHXBi+9+TFY2C6YjruNF7gxL6R6v+9kgFyLdG5zGJt3cMpSb8w4c9B96nrkJYQcrj8rExRfFOkgxlxHwkDEIhxjECgYEA6gCQofgyGNTmOaVEAcWfbyw1CAujgEBKRdgETx0PiXP/jw1L/IU/VvGhL+zKiuAtWm+or1fRXp3yxkqGQHyRR2rta8VMAUL7e28KO+SoO1kr3mrgTa1WqWaZofeAw7vKZ50kmJSfAzzsI1dfXpq8Lnihu+snwmHiin8KPbLjgc0CgYEArf1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6r7JlmKKqvlawIDAQAB";

        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do","2021000122674099",privateKey,"json","UTF-8",publicKey,"RSA2");
        AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
        JSONObject bizContent = new JSONObject();
        bizContent.put("out_trade_no", num);
//bizContent.put("trade_no", "2014112611001004680073956707");
        request.setBizContent(bizContent.toString());
        AlipayTradeQueryResponse response = null;
        try {
            response = alipayClient.execute(request);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        if(response.isSuccess()){
            System.out.println(response.getTradeNo());
            return response.getTradeNo();
        } else {
          return null;
        }
    }

    /**
     * 退款API
     * @param num
     * @param servletResponse
     */
    public static void refund (String num, BigDecimal money,HttpServletResponse servletResponse){
        String privateKey="MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCfCft3kAN4Q9emDemsPK/25AFSgR4G894J3SR2COatUG/biD/qJv0L/HLJJSi6h5MJz7t3LAeAdTeuu6rV4+8xNA0ZG3T8YAso9lLi6GjVp3I33Hg8oh9pJL4wpyh0HHS4fp/zYbj/5DY/Au6qx7ngCWNpfugHLScmoT9aAG3Tbozd04oYn5MplWZApI1Y8fXOL7IZeIFjU9oUTUsPL9ryvqlHYeaNgnhqlYZXPOijDx1cvr5dzoAO0TKfh/M1g6jHVHEptxbl3irg+3ypf+MRncFe/KX0hHGM0MFmQLLlGUhxKBQodr7mpMHdy/plQrIYjS3+9L/qFAwX2LApWbTRAgMBAAECggEBAJojFZo6dHJx5iZlI40vwCdbscBhrVV1s0QCFV1koRVmeRLeyXtJ0ER2plU2c3PdA/Alaf5FKPwiHxZ1gkwMvn0EgpFL4CTdfNN1cL3EHB6+S9/CCLJTOngwCTikOXvXPHS3HJTIqIExkDWfxOq16fstfjD3sy+JXoF9FCZJdifMWMRJB1KSMIx/YDKbsmUebMGCcy6VIeGRnJ8KjuzOxiKO76Myi90oOvzD2DJELS4xUyXYU4Ow+xa4G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UiaeCgmpl6DYK1kCbFw7d/XB4Rktyy3j/xHJoIqvVtWPWmAOLpth3cXZ3JtDwhk7vBY0pj8txyFNLjMGpNO3lWDTkO0JgZAQGrrKE+c2CjKTjDkXLqX+1+FzgWBlt6cZxT2vda2lJNM/9D3Pev7oh54fqomG9DGDWoEQg5KmIxcgKIjDVuy/CCnGeMK3LPry3injykbe4K4AdebLjIp/LhcaRcP6+32YQ45WVXs0j5fBv/jvcdt2KbdYzyhT/iwqF2cFNddg0bf72A9eKik6r7JlmKKqvlawIDAQAB";

        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do","2021000122674099",privateKey,"json","UTF-8",publicKey,"RSA2");
        AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
        JSONObject bizContent = new JSONObject();
        bizContent.put("trade_no", num);
        bizContent.put("refund_amount", money);
        bizContent.put("out_request_no", "HZ01RF001");

//// 返回参数选项，按需传入
//JSONArray queryOptions = new JSONArray();
//queryOptions.add("refund_detail_item_list");
//bizContent.put("query_options", queryOptions);

        request.setBizContent(bizContent.toString());
        AlipayTradeRefundResponse response = null;
        servletResponse.setContentType("text/html;charset=UTF-8");
        try {
            response = alipayClient.execute(request);
            if(response.isSuccess()){
                try {
                    servletResponse.getWriter().write("调用成功");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    servletResponse.getWriter().write("调用失败");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }

    }

    /**
     * 退款查询API
     * @param num
     * @param servletResponse
     * @return
     */
    public static String selectrefund(String num,HttpServletResponse servletResponse){
        String privateKey="MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCfCft3kAN4Q9emDemsPK/25AFSgR4G894J3SR2COatUG/biD/qJv0L/HLJJSi6h5MJz7t3LAeAdTeuu6rV4+8xNA0ZG3T8YAso9lLi6GjVp3I33Hg8oh9pJL4wpyh0HHS4fp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civYxp+AECgYEApzGAby+eQBIjHwwgRJz5uBMalkJMBbYwjhtlWAQ6rLTSXbvnueZouZ9hCpiLwJEtx/FF57GOMfDuvS9ihtJ2zPEfGKjh+5lpoVGgPpDKIiasVXEuxy+1GElB1kYdqNWD/hKXTY/GNbQf3QXYT0GYr2aG3dFsn4d1oa10CLpdgxUCgYBxMYxToAd5s0UoblYbhiXVIsDNUMw6RdTSCEpplNA6ZAAwuz+nNneb6BoEcqR4HJS8Ut1Tv3y8Aryp7EtuANSlqBTfR1CWHQ38ICAFumb77mXQjjXMn2sIb0iPJoEFNJazwsfTYdfK5x6UKE5TaclXWDaBi/9uDHqea67z3Sobcw==";
        String publicKey="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgjFVGgLgFAqb+UBZJte4bRobFT+LF2XDuIkmr96g+cb80QW0wkJZeeUiaeCgmpl6DYK1kCbFw7d/XB4Rktyy3j/xHJoIqvVtWPWmAOLpth3cXZ3JtDwhk7vBY0pj8txyFNLjMGpNO3lWDTkO0JgZAQGrrKE+c2CjKTjDkXLqX+1+FzgWBlt6cZxT2vda2lJNM/9D3Pev7oh54fqomG9DGDWoEQg5KmIxcgKIjDVuy/CCnGeMK3LPry3injykbe4K4AdebLjIp/LhcaRcP6+32YQ45WVXs0j5fBv/jvcdt2KbdYzyhT/iwqF2cFNddg0bf72A9eKik6r7JlmKKqvlawIDAQAB";
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do","2021000122674099",privateKey,"json","UTF-8",publicKey,"RSA2");
        AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest();
        JSONObject bizContent = new JSONObject();
        bizContent.put("trade_no", num);
        bizContent.put("out_request_no", "HZ01RF001");

//// 返回参数选项，按需传入
//JSONArray queryOptions = new JSONArray();
//queryOptions.add("refund_detail_item_list");
//bizContent.put("query_options", queryOptions);

        request.setBizContent(bizContent.toString());
        AlipayTradeFastpayRefundQueryResponse response = null;
        servletResponse.setContentType("text/html;charset=UTF-8");
        try {
            response = alipayClient.execute(request);
            if(response.isSuccess()){
                try {
                    servletResponse.getWriter().write("退款成功");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    servletResponse.getWriter().write("退款失败");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
      return  null;
    }

}
